package com.asianrapid.controller.sys;


import com.asianrapid.model.sys.LqrjEntity;
import com.asianrapid.model.sys.LqrzEntity;
import com.asianrapid.model.sys.PageResult;
import com.asianrapid.service.sys.LqrjService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class LqrjController {

    private Logger log = LoggerFactory.getLogger(LqrjController.class);

    @Autowired
    private LqrjService lqrjService;
    /*查出所有信息*/
    @GetMapping("/lqrjs")
    public PageResult getalllqrj(int pageSize, int page){

        PageResult pageResult = new PageResult();
        List<LqrjEntity> alllqrj = lqrjService.getalllqrj(pageSize, page * pageSize);
        int total= lqrjService.getCount();
        pageResult.setData(alllqrj);
        pageResult.setTotalCount(total);
        return pageResult;
    }
    /*新增信息*/
    @PostMapping("/insertlqrj")
    public void insert (@RequestBody LqrjEntity lqrjEntity){
        System.out.println(lqrjEntity);
        lqrjService.insertlqrj(lqrjEntity);
    }
    /*修改信息*/
    @PutMapping("/updatelqrj/{id}")
    public LqrjEntity update(@RequestBody LqrjEntity lqrjEntity, @RequestBody int id){
        if (lqrjEntity.getId() == id){
        lqrjService.updatelqrj(lqrjEntity);
        }

        return lqrjEntity;
    }

    @PostMapping("/getById")
    public LqrjEntity getById(@RequestBody List<Integer> groupId){


        return  lqrjService.getById(groupId.get(0));
    }


    /*删除信息*/
    @DeleteMapping("/deletelqrj")
    public List<String> delete(@RequestBody List<String> groupId){
        lqrjService.deletelqrj(groupId);
        return groupId;
    }
}
